package com.xiaoma.tpo.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.ChChapter;

@Repository
public class ChChapterDao extends BaseDaoImpl<ChChapter>{

    private static final Logger LOG = LoggerFactory.getLogger(ChChapterDao.class);
    
    @SuppressWarnings("unchecked")
    public List<ChChapter> findByTpoId(int tpoId) {
        String sql = "SELECT * FROM ch_chapter WHERE id in (SELECT ch_chapter_id FROM ch_tpo_chapter where ch_tpo_id = ?)";
        LOG.info("SQL:{} PARAMS:{}", sql, tpoId);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(ChChapter.class, getNameHandler()), tpoId);
        return (List<ChChapter>)result;
    }
}
